 $(function(){
	$('#switch_qlogin').click(function(){
		$('#switch_login').removeClass("switch_btn_focus").addClass('switch_btn');
		$('#switch_qlogin').removeClass("switch_btn").addClass('switch_btn_focus');
		$('#switch_bottom').animate({left:'0px',width:'70px'});
		$('#qlogin').css('display','none');
		$('#web_qr_login').css('display','block');
		
		});
	$('#switch_login').click(function(){
		
		$('#switch_login').removeClass("switch_btn").addClass('switch_btn_focus');
		$('#switch_qlogin').removeClass("switch_btn_focus").addClass('switch_btn');
		$('#switch_bottom').animate({left:'154px',width:'70px'});
		
		$('#qlogin').css('display','block');
		$('#web_qr_login').css('display','none');
		});
	if(getParam("a")=='0'){
		$('#switch_login').trigger('click');
	}
	
	$("#dologin").click(function(){
		var mobile = $("#mobile").val();
		var password = $("#password").val();
		var callback = $("#callback").val();
		var token = $("#token").val();
		if (mobile == "") {
			layer.alert("手机号不能为空");
			return false;
		}
		
		if (mobile.length < 10 || mobile.length > 12) {
			layer.alert("手机号不正确");
			return false;
		}
		
		$.post('/dologin.html',{'mobile':mobile,'password':password,'_token':token},function(response){
            if(response.error){
                layer.alert(response.msg);
                return;
            }
            window.location.href = callback;
        },'json');
    })
    
    $(".Get-code").click(function() {
     	var mobile = $("#reg_mobile").val();
     	var token = $("#token").val();
     	var userCue = $('#userCue');
     	if (mobile == "") {
     		$('#reg_mobile').focus().css({border: "1px solid red",boxShadow: "0 0 2px red"});
     		userCue.html("<font color='red'><b>×手机号不能为空</b></font>");
     		return false;
     	}
     	
     	if (mobile.length < 10 || mobile.length > 12) {
     		$('#reg_mobile').focus().css({border: "1px solid red",boxShadow: "0 0 2px red"});
     		userCue.html("<font color='red'><b>×手机号不正确</b></font>");
     		return false;
     	}
     		
     	$.post('/user/sendmessage',{'mobile':mobile,'_token':token},function(response){
     		if(response.error){
     			userCue.html("<font color='red'><b>"+response.msg+"</b></font>");
     			return;
     		}
     		var othis = $(".Get-code");
     		othis.addClass("oncode");
     		var index = 60;
     		var time = setInterval(function() {
     			if (index == 0) {
     				othis.html("重新获取").removeClass("oncode");
     				clearInterval(time);
     				return false;
     			}
     			--index;
     			othis.html("重新获取" + index + "秒");
     		}, 1000)
     		userCue.html("<font color='green'><b>已发送，1分钟后可重新获取。</b></font>");
     	},'json');
     }) 
     
     $("#doreg").click(function(){
		var mobile = $("#reg_mobile").val();
		var code = $("#code").val();
		var password = $("#reg_password").val();
		var repassword = $("#reg_repassword").val();
		var callback = $("#callback").val();
		var token = $("#token").val();
		
		if (mobile == "") {
			$('#reg_mobile').focus().css({border: "1px solid red",boxShadow: "0 0 2px red"});
			$('#userCue').html("<font color='red'><b>×手机号不能为空</b></font>");
			return false;
		}
		
		if (mobile.length < 10 || mobile.length > 12) {
			$('#reg_mobile').focus().css({border: "1px solid red",boxShadow: "0 0 2px red"});
			$('#userCue').html("<font color='red'><b>×手机号不正确</b></font>");
			return false;
		}

		if (password.length < 6) {
			$('#reg_password').focus();
			$('#userCue').html("<font color='red'><b>×密码不能小于6位</b></font>");
			return false;
		}
		
		if(password != repassword){
			$('#reg_repassword').focus();
			$('#userCue').html("<font color='red'><b>两次密码并不一致</b></font>");
			return;
		}
		
		$.post('/doreg.html',{'mobile':mobile,'code':code,'password':password,'repassword':repassword,'_token':token},function(response){
            if(response.error){
                $('#userCue').html("<font color='red'><b>"+response.msg+"</b></font>");
                return;
            }
            $('#userCue').html("<font color='green'><b>注册成功</b></font>");
            window.location.href = callback;
        },'json');
	})
    
	
	$(".Get-code-set").click(function() {
     	var mobile = $("#mobile").val();
     	var token = $("#token").val();
     	var userCue = $('#userCue');
     	if (mobile == "") {
     		$('#mobile').focus().css({border: "1px solid red",boxShadow: "0 0 2px red"});
     		userCue.html("<font color='red'><b>×手机号不能为空</b></font>");
     		return false;
     	}
     	
     	if (mobile.length < 10 || mobile.length > 12) {
     		$('#mobile').focus().css({border: "1px solid red",boxShadow: "0 0 2px red"});
     		userCue.html("<font color='red'><b>×手机号不正确</b></font>");
     		return false;
     	}
     		
     	$.post('/user/sendmessage',{'mobile':mobile,'type':2, '_token':token},function(response){
     		if(response.error){
     			userCue.html("<font color='red'><b>"+response.msg+"</b></font>");
     			return;
     		}
     		var othis = $(".Get-code-set");
     		othis.addClass("oncode");
     		var index = 60;
     		var time = setInterval(function() {
     			if (index == 0) {
     				othis.html("重新获取").removeClass("oncode");
     				clearInterval(time);
     				return false;
     			}
     			--index;
     			othis.html("重新获取" + index + "秒");
     		}, 1000)
     		userCue.html("<font color='green'><b>已发送，1分钟后可重新获取。</b></font>");
     	},'json');
     }) 
	
	$("#doset").click(function(){
		var mobile = $("#mobile").val();
		var code = $("#code").val();
		var password = $("#password").val();
		var repassword = $("#repassword").val();
		var callback = $("#callback").val();
		var token = $("#token").val();
		
		if (mobile == "") {
			$('#mobile').focus().css({border: "1px solid red",boxShadow: "0 0 2px red"});
			$('#userCue').html("<font color='red'><b>×手机号不能为空</b></font>");
			return false;
		} else {
			$('#mobile').focus().css({border: "1px solid green",boxShadow: "0 0 2px green"});
		}
		
		if (mobile.length < 10 || mobile.length > 12) {
			$('#mobile').focus().css({border: "1px solid red",boxShadow: "0 0 2px red"});
			$('#userCue').html("<font color='red'><b>×手机号不正确</b></font>");
			return false;
		}

		if (password.length < 6) {
			$('#password').focus().css({border: "1px solid red",boxShadow: "0 0 2px red"});
			$('#userCue').html("<font color='red'><b>×密码不能小于6位</b></font>");
			return false;
		}
		
		if(password != repassword){
			$('#repassword').focus().css({border: "1px solid red",boxShadow: "0 0 2px red"});
			$('#userCue').html("<font color='red'><b>两次密码并不一致</b></font>");
			return;
		}
		
		$.post('/dofindpwd.html',{'mobile':mobile,'code':code,'password':password,'repassword':repassword,'_token':token},function(response){
            if(response.error){
                $('#userCue').html("<font color='red'><b>"+response.msg+"</b></font>");
                return;
            }
            $('#userCue').html("<font color='green'><b>密码修改成功</b></font>");
            window.location.href = callback;
        },'json');
	})
	
	$(".Get-code-up").click(function() {
     	var mobile = $("#mobile").val();
     	var token = $("#token").val();
     	var userCue = $('#userCue');
     	if (mobile == "") {
     		$('#mobile').focus().css({border: "1px solid red",boxShadow: "0 0 2px red"});
     		userCue.html("<font color='red'><b>×手机号不能为空</b></font>");
     		return false;
     	}
     	
     	if (mobile.length < 10 || mobile.length > 12) {
     		$('#mobile').focus().css({border: "1px solid red",boxShadow: "0 0 2px red"});
     		userCue.html("<font color='red'><b>×手机号不正确</b></font>");
     		return false;
     	}
     		
     	$.post('/user/sendmessage',{'mobile':mobile,'type':3, '_token':token},function(response){
     		if(response.error){
     			userCue.html("<font color='red'><b>"+response.msg+"</b></font>");
     			return;
     		}
     		var othis = $(".Get-code-up");
     		othis.addClass("oncode");
     		var index = 60;
     		var time = setInterval(function() {
     			if (index == 0) {
     				othis.html("重新获取").removeClass("oncode");
     				clearInterval(time);
     				return false;
     			}
     			--index;
     			othis.html("重新获取" + index + "秒");
     		}, 1000)
     		userCue.html("<font color='green'><b>已发送，1分钟后可重新获取。</b></font>");
     	},'json');
     }) 
	
     $("#doupdate").click(function(){
		var mobile = $("#mobile").val();
		var code = $("#code").val();
		var password = $("#password").val();
		var repassword = $("#repassword").val();
		var callback = $("#callback").val();
		var token = $("#token").val();
		
		if (mobile == "") {
			$('#mobile').focus().css({border: "1px solid red",boxShadow: "0 0 2px red"});
			$('#userCue').html("<font color='red'><b>×手机号不能为空</b></font>");
			return false;
		} else {
			$('#mobile').focus().css({border: "1px solid green",boxShadow: "0 0 2px green"});
		}
		
		if (mobile.length < 10 || mobile.length > 12) {
			$('#mobile').focus().css({border: "1px solid red",boxShadow: "0 0 2px red"});
			$('#userCue').html("<font color='red'><b>×手机号不正确</b></font>");
			return false;
		}

		if (password.length < 6) {
			$('#password').focus().css({border: "1px solid red",boxShadow: "0 0 2px red"});
			$('#userCue').html("<font color='red'><b>×密码不能小于6位</b></font>");
			return false;
		}
		
		if(password != repassword){
			$('#repassword').focus().css({border: "1px solid red",boxShadow: "0 0 2px red"});
			$('#userCue').html("<font color='red'><b>两次密码并不一致</b></font>");
			return;
		}
		
		$.post('/user/domodifypwd.html',{'mobile':mobile,'code':code,'password':password,'repassword':repassword,'_token':token},function(response){
            if(response.error){
                $('#userCue').html("<font color='red'><b>"+response.msg+"</b></font>");
                return;
            }
            $('#userCue').html("<font color='green'><b>密码修改成功</b></font>");
            layer.alert(response.msg);
            location.reload();
        },'json');
	})
});


 
 
function logintab(){
	scrollTo(0);
	$('#switch_qlogin').removeClass("switch_btn_focus").addClass('switch_btn');
	$('#switch_login').removeClass("switch_btn").addClass('switch_btn_focus');
	$('#switch_bottom').animate({left:'154px',width:'96px'});
	$('#qlogin').css('display','none');
	$('#web_qr_login').css('display','block');
	
}


//根据参数名获得该参数 pname等于想要的参数名 
function getParam(pname) { 
    var params = location.search.substr(1); // 获取参数 平且去掉？ 
    var ArrParam = params.split('&'); 
    if (ArrParam.length == 1) { 
        //只有一个参数的情况 
        return params.split('=')[1]; 
    } 
    else { 
         //多个参数参数的情况 
        for (var i = 0; i < ArrParam.length; i++) { 
            if (ArrParam[i].split('=')[0] == pname) { 
                return ArrParam[i].split('=')[1]; 
            } 
        } 
    } 
}  
